﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;

public partial class SendMessage : System.Web.UI.Page
{
    SqlConnection cn;
    string username;
    int userid;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["uid"] == null)
        {
            Response.Redirect("../GUI/Home.aspx");
        }
        else
           
        {
            username = (string)Session["uid"];
            userid = ToolsDT.getUserID(username);
        }
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {

            string mobile = txtPhone.Text.ToString();
            string detail = txtContent.Text.ToString();
            if (!ToolsDT.checkTel(mobile))
            {
                Response.Write(@"<script language='javascript'>alert('mobile number not valid')</script>");
                txtPhone.Focus();
                return;
            }
            try
            {
                cn = ToolsDT.getConnect();
                SqlCommand cmd = new SqlCommand("sp_SendMessageToMobile", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@userid", SqlDbType.Int);
                cmd.Parameters.Add("@mobile", SqlDbType.VarChar, 10);
                cmd.Parameters.Add("@detail", SqlDbType.VarChar, 200);
                cmd.Parameters["@userid"].Value = userid;
                cmd.Parameters["@mobile"].Value = mobile;
                cmd.Parameters["@detail"].Value = detail;
                cmd.ExecuteNonQuery();
            }
            catch
            {
                
            } 
        finally
        {
            cn.Close();
            Response.Write(@"<script language='javascript'>alert('Send message is successful.')</script>");
        }
           
    
    }

  
}
